package map;

import java.util.*;

/**
 * 遍历map，以集合的形式；
 */
public class MapDemo2 {

public static void main(String[] args) {
    Map<String ,Integer> map = new HashMap<>();
    map.put("语文",100);
    map.put("数学",99);
    map.put("英语",88);
    map.put("物理",99);
    map.put("化学",99);

    //遍历map
    //keyset()  存key的集合。不能重复
    Set<String> keySet = map.keySet();
    for(String key:keySet){
        System.out.println("key:"+key);
    }

    //entry对象————key，value，不能重复
    Set<Map.Entry<String ,Integer>> entry = map.entrySet();
    for(Map.Entry<String ,Integer> e:entry){
        String key=e.getKey();
        Integer value = e.getValue();
        System.out.println(key + ":" + value);
    }

    //
    Collection<Integer> values = map.values();
    for(Integer value :values){
        System.out.println("value:"+value);
    }

    Collection<String > c = new ArrayList<>();
    c.add("jeag");
    c.add("jeag");
    c.add("jeag");
    c.add("jeag");
    c.add("jeag");
    c.forEach(e->
                    System.out.println(e)
            );

    //forEach()
    map.forEach(
            (k,v)-> System.out.println(k + ":" +v)
    );

}
}
